<?php
/**
 * 盆景预约模版消息发送
 *
 * @author hjc19850430@gmail.com
 */
class BonsaiMsgtpl extends BaseMsgtpl
{
    /**
     * 预约成功微信信息模版推送
     * @param array $orderData   订单基础信息
     * @param array $orderGoods  订单商品信息
     * @return void
     */
    public function messageTpl($orderData, $orderGoods)
    {
        //目前管理员设为1690 A奔跑的小摊主;

        $maneger = array(1488, 996, 645, 1690);
        $this->wxTplSign = 'En2hbZ6GDZsh3DR_DaQWlFsr98HUDU9kLBkolfcVN-A';
        
        $arr = '';
        foreach($orderGoods as $key => $val) {
            $arr .= $val['goods_name'] . '、';
        }
        $arr = rtrim($arr, "、");

        if($orderData['solution'] != 1) {
            $keyword3 = '客户' . $orderData['username'] . '预约了【' . $arr . '】盆景，预估总费用' . $orderData['order_amount'] . '元';
        } else {
            if($orderData['type'] != 2) {
                $keyword3 = '客户' . $orderData['username'] . '预约了' . date("Y年m月d日", $orderData['use_start_time']) . '至' . date("Y年m月d日", $orderData['use_end_time']) . '期间,为期' . $orderData['use_long'] . '天的盆景';
            } else {
                $keyword3 = '客户' . $orderData['username'] . '预约了' . date("Y年m月d日", $orderData['use_start_time']) . '至' . date("Y年m月d日", $orderData['use_end_time']) . '期间的盆景';
            }
        }

        $type = '';
        if($orderData['type'] == 2) {
            $type = '会场';
        } elseif($orderData['type'] == 3) {
            $type = '长期';
        }
        if($orderData['solution'] == 1) {
            $solution = '服务商提供方案';
        } elseif($orderData['solution'] == 0) {
            $solution = '自主选择方案';
        }
        $info = array(
            'first' => array("value" => '管理员您好，您有新的盆景预约订单'),
            'keyword1' => array("value" => '盆景预约'),
            'keyword2' => array("value" => date("Y-m-d H:i:s", $orderData['create_time'])),
            'keyword3' => array("value" => $keyword3),
            'remark' => array("value" => "下单者姓名：" . $orderData['username'] . "\n联系电话：" . $orderData['mobile'] . "\n订单类型：" . $type . $solution . "\n请及时处理确定方案"),
        );
        $wechat = D('Wechat')->get(session('wechat_id'));

        
        foreach($maneger as $v) {
            $fans = D('Fans')->get($v, 'openid,subscribe');
            if($fans['subscribe']) {
// 			$url = "http://wap.xt.beescrm.com/base/bonsai/orderdetail/wechat_id/".$this->wechat_id."/order_id/".$orderData['order_id'];

                $result = $this->wxObj->messageTpl($wechat['appid'], $wechat['appsecret'], $fans['openid'], $this->wxTplSign, $info);
            }
        }
    }
}
